package com.olddriver.crm.web.controller;

import com.olddriver.crm.annotation.PermissionName;
import com.olddriver.crm.domain.CompensationDetails;
import com.olddriver.crm.page.PageResult;
import com.olddriver.crm.query.CompensationDetailsQueryObject;
import com.olddriver.crm.query.QueryObject;
import com.olddriver.crm.service.ICompensationDetailsService;
import com.olddriver.crm.service.ITotalInfoService;
import com.olddriver.crm.util.JsonResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("compensationDetails")
public class CompensationDetailsController {

    @Autowired
    private ICompensationDetailsService detailsService;
    @Autowired
    private ITotalInfoService totalInfoService;

    @RequestMapping("list")
    @RequiresPermissions("compensationDetails:list")
    @PermissionName("查看理赔明细")
    public String list() {
        return "compensationDetails/list";
    }

    @ResponseBody
    @RequestMapping("query")
    @RequiresPermissions("compensationDetails:query")
    @PermissionName("理赔明细列表")
    public PageResult query(QueryObject qo) {
        PageResult result = detailsService.query(qo);
        return result;
    }

    @ResponseBody
    @RequestMapping("saveOrUpdate")
    @RequiresPermissions("compensationDetails:saveOrUpdate")
    @PermissionName("理赔明细编辑")
    public JsonResult saveOrUpdate(CompensationDetails details, String sn) {
        Long id = details.getId();
        try {
            if (id != null) {
                detailsService.updateByPrimaryKey(details);

            } else {
                detailsService.insert(details, sn);
            }
            return JsonResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.faliure();
        }
    }


    @RequestMapping("lookDetails")
    @ResponseBody
    public CompensationDetails lookDetails(String sn) {
        CompensationDetails details = detailsService.selectDetailBySn(sn);
        return details;
    }
}







